package RJ;

import java.util.*;

public class Person implements Comparable{
	
	String name;
	ROLE role;
	boolean smoker=false;
	boolean hacker=false;
	Group group;
	Project project;
	HashSet<Person> WorkWith;
	
	boolean isHead;	

 
	public Person(String p) {
		this.name=p;
		WorkWith = new HashSet<Person>();
		isHead = false;
	}
	
	public boolean isHead(){
		return isHead;
	}
	
	public void setIsHead(boolean b){
		isHead = b;
	}

	public Project getProject() {
		return project;
	}

	public void setProject(Project project) {
		if(this.project==null){
			this.project = project;
			project.getProjectMembers().add(Person.this);
		}else{
			this.project.getProjectMembers().remove(Person.this);
			this.project = project;
			project.getProjectMembers().add(Person.this);
		}
		
	}

	public Group getGroup() {
		return group;
	}

	public void setGroup(Group group) {
		if(this.group == null){
			this.group = group;
		}else{
			this.group.groupMember.remove(Person.this);
			this.group = group;
		}
		if(this.role==ROLE.MANAGER&&this.group!=null){
			this.group.setGroupManager(Person.this);
		}
		group.groupMember.add(Person.this);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public ROLE getRole() {
		return role;
	}

	public void setRole(ROLE role) {
		this.role = role;
		if(role==ROLE.MANAGER&&this.group!=null){
			this.group.setGroupManager(Person.this);
		}
	}

	public boolean isSmoker() {
		return smoker;
	}

	public void setSmoker(boolean smoker) {
		this.smoker = smoker;
	}

	public boolean isHacker() {
		return hacker;
	}

	public void setHacker(boolean hacker) {
		this.hacker = hacker;
	}

	@Override
	public int compareTo(Object o) {
		Person per = (Person) o;
		return (this.name.compareTo(per.name));
	}
	@Override
	public String toString(){
		String s="";
		s += String.format("person(%s)\n", this.getName());
		if(this.isHacker())			s += String.format("hacker(%s)\n", this.getName());
		if(this.isSmoker())			s += String.format("smoker(%s)\n", this.getName());
		if(this.getRole()!=null)	s += String.format(this.getRole().toString().toLowerCase() + "(%s)\n", this.getName());
		String t = "";
		for(Person p: WorkWith)		t += p.getName() + ", ";
		if(t.length()>0)	t = t.substring(0,t.length() -2);
		s += String.format("works-with(%s, {%s})\n", this.getName(),t);
		if(group!=null)
			s += String.format("group(%s, %s)\n", this.getName(),this.getGroup().name);
		if(project!=null)
			s += String.format("project(%s, %s)\n", this.getName(),this.getProject().name);
		return s;
	}
	

}
